import 'package:architecture/os_size.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:lottie/lottie.dart';

import 'controller.dart';

class LottiePage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return GetBuilder<LottieController>(
        init: LottieController(),
        builder: (controller) {
          return Scaffold(
              appBar: AppBar(title: Text('Lottie')),
              body: Container(
                  margin: EdgeInsets.all(10),
                  child: SingleChildScrollView(
                      child: GridView.builder(
                          itemCount: controller.lotties.length,
                          shrinkWrap: true,
                          physics: new NeverScrollableScrollPhysics(),
                          gridDelegate:
                              SliverGridDelegateWithFixedCrossAxisCount(
                                  //横轴元素个数
                                  crossAxisCount: 3,
                                  //纵轴间距
                                  mainAxisSpacing: 15.0,
                                  //横轴间距
                                  crossAxisSpacing: 15),
                          itemBuilder: (BuildContext context, int index) {
                            //Widget Function(BuildContext context, int index)
                            return _itemLayout(index, controller);
                          }))));
        });
  }

  _itemLayout(int index, LottieController controller) {
    return Container(
        width: windowWidth,
        alignment: Alignment.center,
        child: Lottie.asset(controller.lotties.elementAt(index)));
  }
}
